#include <iostream>
#include <vector>

using namespace std;

class Solution 
{
public:
    int minSubArrayLen(int target, vector<int>& nums) 
    {
        int size = nums.size();
        int front = 0, back = 0;
        int min_length = 0;
        int sum = nums[0];
        while(front < size)
        {
            if(sum < target)
            {
                front++;
                if(front < size)
                {
                    sum += nums[front];
                }
            }
            else
            {
                if(front == back)
                {
                    return 1;
                }
                int temp_length = front - back + 1;
                if(min_length == 0)
                {
                    min_length = temp_length;
                }
                min_length = min_length < temp_length ? min_length : temp_length;
                sum -= nums[back];
                back++;
            }
        }
        return min_length;
    }
};

int main()
{
    Solution s;
    
    // 测试案例1：基本测试案例
    vector<int> nums1 = {2, 3, 1, 2, 4, 3};
    int target1 = 7;
    cout << "原始数组: ";
    for(int num : nums1) {
        cout << num << " ";
    }
    cout << endl;
    cout << "目标值: " << target1 << endl;
    
    int result1 = s.minSubArrayLen(target1, nums1);
    cout << "最小子数组长度: " << result1 << endl; // 输出: 2 (子数组 [4,3])
    
    // 测试案例2：找不到满足条件的子数组
    vector<int> nums2 = {1, 1, 1, 1, 1, 1, 1, 1};
    int target2 = 11;
    cout << "\n原始数组: ";
    for(int num : nums2) {
        cout << num << " ";
    }
    cout << endl;
    cout << "目标值: " << target2 << endl;
    
    int result2 = s.minSubArrayLen(target2, nums2);
    cout << "最小子数组长度: " << result2 << endl; // 输出: 0 (找不到满足条件的子数组)
    
    return 0;
}
